<template>
  <header class="header">
    <h1>todos</h1>
    <input v-model="isAll" id="toggle-all" class="toggle-all" type="checkbox" />
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      :value="tit"
      @change="handerchange"
      @keyup.enter="addList"
    />
  </header>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  data() {
    return {
      is: false,
    };
  },
  computed: {
    ...mapState(["list", "tit"]),
    isAll: {
      set(val) {
        this.GaiChe(val);
      },
      get() {
        return this.$store.state.list.every(item =>
        item.done === true)
      },
    },
  },
  methods: {
    ...mapMutations(["addnewList", "getInput","GaiChe"]),
    handerchange(e) {
      this.$store.commit("getInput", e.target.value);
    },
    addList() {
      if (this.tit.trim().length === 0) {
        return alert("Please selected");
      }

      this.addnewList();
    },
  },
};
</script>

<style></style>
